package com.clouddot.baipai.ui.adapter.V_Adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.clouddot.baipai.R;
import com.clouddot.baipai.model.beam.getArcticList.ariticInfo;

import java.util.List;

/**
 * Created by wxy on 2018/3/29.
 */

public class V_NewsRecyclerAdapter extends RecyclerView.Adapter<V_NewsRecyclerAdapter.MyViewHolder> {
    private Context context;
    private List<ariticInfo> list;
    public V_NewsRecyclerAdapter(Context context, List<ariticInfo> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                context).inflate(R.layout.v_l_newsadapteritem, parent,
                false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.tv1.setText(list.get(position).getTitle());
        holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                btnclicker.onClicked(position);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView tv1 ,tv2;
        private RelativeLayout relativeLayout;

        public MyViewHolder(View view) {
            super(view);
            tv1 = view.findViewById(R.id.tv1);
            tv2 = view.findViewById(R.id.tv2);
            relativeLayout = view.findViewById(R.id.relat);

        }
    }
    public interface btnOnclicker {
        void onClicked(int position);
    }

    private  btnOnclicker btnclicker;

    public void setbtnOnclicker(btnOnclicker btnclicker) {
        this.btnclicker = btnclicker;
    }

}

